package com.example.javalib.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

public class date1 {

    public static void main(String[] args) {
        long t=getStringToDate("2020-05-25","yyyy-MM-dd");
        System.out.println("t = " + t);
        String s=getDateToString(t,"yyyy-MM-dd");
        System.out.println("s:"+s);
        System.out.println("你好");
    }

    /**
     * 秒转时间
     * @param dateString
     * @param pattern
     * @return
     */
    public static long getStringToDate(String dateString, String pattern) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
        Date date = new Date();
        try{
            date = dateFormat.parse(dateString);
        } catch(ParseException e) {
            e.printStackTrace();
        }
        return date.getTime();
    }

    /**
     * 日期转秒
     * @param milSecond
     * @param pattern
     * @return
     */
    public static String getDateToString(long milSecond, String pattern) {
        Date date = new Date(milSecond);
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }


}
